package beans.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class LogHandler implements InvocationHandler
{

	private final Object obj;

	public LogHandler(Object obj)
	{
		super();
		this.obj = obj;
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
	{
		doBefore();
		Object result = method.invoke(obj, args);
		if (result != null)
		{
			System.out.println(result);
		}
		after();
		return result;
	}

	public void doBefore()
	{
		System.out.println("LogHandler.doBefore();");
	}

	public void after()
	{
		System.out.println("LogHandler.after();");
	}

}
